package com.xyht.medicine_management_system.modules.medicine.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.annotation.RequestPass;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.medicine.entity.req.MmsMedicineHotAddListReq;
import com.xyht.medicine_management_system.modules.medicine.entity.req.MmsMedicineHotDeletedReq;
import com.xyht.medicine_management_system.modules.medicine.service.MmsMedicineHotService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 热销药品 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-04
 */
@RestController
@SecretBody
@RequestMapping("/medicine/hot")
public class MmsMedicineHotController {

    @Resource
    private MmsMedicineHotService medicineHotService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加热销药品")
    @PostMapping("/add")
    public ResponseResult addMedicineHot(@RequestBody MmsMedicineHotAddListReq addListReq, HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return medicineHotService.addMedicineHot(addListReq,userId);
    }

    @ApiModelProperty("删除热销药品")
    @PostMapping("/deleted")
    public ResponseResult deletedMedicineHot(@RequestBody MmsMedicineHotDeletedReq deletedReq){
        return medicineHotService.deletedMedicineHot(deletedReq);
    }

    @ApiModelProperty("查看热销药品列表")
    @GetMapping("/list")
    @RequestPass
    public ResponseResult getMedicineHotList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "isOn",required = false) Integer isOn,
                                             @RequestParam(value = "name",required = false) String name,
                                             HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdOrNullByRequest(request);
        return medicineHotService.getMedicineHotList(pageNum,pageSize,name,isOn,userId);
    }



}

